﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class TreePath : WebControl
    {
        public TreePath()
        {
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            string str = TreeTables.TreeTable(TreeType).GetPathText(CategoryId, Split, 0);
            if (!string.IsNullOrEmpty(Format) && !string.IsNullOrEmpty(str))
            {
                str = Split + str;
                str = string.Format(ResourceManagement.Content.Strings[Format], str);
            }
            writer.Write(str);
        }

        private int categoryId = -1;
        public int CategoryId
        {
            get
            {
                if (categoryId >= 0)
                    return categoryId;
                else
                    return SiteContext.Current.CategoryId;
            }
            set
            {
                categoryId = value;
            }
        }

        private string split = " > ";
        public string Split 
        {
            get
            {
                return split;
            }
            set
            {
                split = value;
            }
        }

        public TreeTableType TreeType { get; set; }

        /// <summary>
        /// Resource.xml 中的 name
        /// </summary>
        public string Format{get;set;}
    }

    
}
